//单位时间内执行一次
function debounce(fn, t) {
  let timer;
  return function (...arg) {
    if (timer) {
      timer = null;
    }
    timer = setTimeout(() => {
      fn.apply(this, arg);
    }, t);
  };
}

debounce();

/* const obj = {
  name: "Lucas",
  sayHi() {
    console.log("hi", this.name);
  }
};

const debounced = debounce(obj.sayHi, 500);
debounced();  */ //! ❌ this 丢失，输出 "hi undefined" 不写
